/**
 *
 *embustest message process .h.
 *
 * @remarks
 * 2022 created by yy.
 */

#ifndef _MSGPROCTEST_H_
#define _MSGPROCTEST_H_

#include <stdio.h>
#include <time.h>
#include <iostream>
#include <chrono>
#include <thread>
#include <cstring>
#include <stdint.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stdbool.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>
#include <map>
#include "libembus.h"
#include "packet.h"

#define LOGGING_FLAG 0

struct log_packet
{
    struct com_packet frame;
    uint64_t count;
};

using namespace std;

int StringtoHex(char *str, unsigned char *out);
void get_format_time_st(uint64_t timestamp, char *time_str);

void show_can_com_framemap_info();
void update_can_com_framemap_info(struct com_packet* pac);
void show_can_com_frame_msg(struct com_packet* pac, string g_channel, FILE *fp);
void show_lin_com_frame_msg(struct com_packet* pac, string g_channel, FILE *fp);
void show_vio_status_msg(struct vio_status* pac, string g_channel);
void show_com_status_msg(struct com_status* pac, string g_channel);
void show_com_event_msg(struct com_event* pac, string g_channel);
void show_gps_data_msg(struct gps_data* pac);
void show_state_data_msg(struct rmu_state* pac);
void get_state_data_msg(struct rmu_state* pac);

int msg_tx_canmsg_test(embus_handle_t* handle, string channel, int loop, int interval, string frame);
int msg_tx_canconfig_test(embus_handle_t* handle, string channel, uint32_t baudrate, uint32_t dbaudrate, uint8_t sample, uint8_t dsample);
int msg_tx_cansetmode_test(embus_handle_t* handle, string channel, uint8_t mode);
int msg_tx_linconfig_test(embus_handle_t* handle, string channel, uint16_t rate);
int msg_tx_linsetmode_test(embus_handle_t* handle, string channel, uint8_t mode);
int msg_tx_DoipPowerOnInitSet_test(embus_handle_t* handle, uint8_t state);
int msg_tx_DoipSet_test(embus_handle_t* handle, uint8_t state);

int msg_tx_RTCwakeup_test(embus_handle_t* handle, string wk_time, uint8_t wk_mode);
int msg_tx_DOstate_test(embus_handle_t* handle, string DOctl, string DOstate);
int msg_tx_LEDctrl_test(embus_handle_t* handle, string LEDctl, string LEDstate);
int msg_tx_BUZctrl_test(embus_handle_t* handle, uint32_t BUZstate);
int msg_tx_sleep_enable_test(embus_handle_t* handle, string mode);
int msg_tx_ota_test(embus_handle_t* handle, uint8_t req);
int get_ign_state();

#endif